﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace FillCartridgeBBB.HtmlHelpers
{
    public static class PagingHelpers
    {
        public static string PageLinks (this HtmlHelper html,int currentPage, int totalPage, Func<int,string> pageUrl)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 0; i < totalPage; i++)
            {
                TagBuilder tg = new TagBuilder("a");
                tg.MergeAttribute("href", pageUrl(i));
                tg.InnerHtml = i.ToString();
                if (i == currentPage)
                {
                    tg.AddCssClass("selected");
                }
                result.AppendLine(tg.ToString());
            }
            return result.ToString();
        }
    }
}
